package com.gancai.model.menu;

import lombok.Getter;

import java.util.Map;

/**
 * @author GanGan
 */
public enum PlatformCodeEnum {
    SUCCESS(200,"success"),
    ERROR(500,"error");

    @Getter
    private final int code;
    @Getter
    private final String message;


    // 构造器私有化，防止外部创建实例
    PlatformCodeEnum(int code, String mesage) {
        this.code = code;
        this.message = mesage;
    }

    public static PlatformCodeEnum fromCode(int code) {
        for (PlatformCodeEnum status : values()) {
            if (status.code == code) {
                return status;
            }
        }
        throw new IllegalArgumentException("无效的状态码: " + code);
    }

    public boolean isSuccess() {
        return code >= 200 && code < 300;
    }

    public boolean isError() {
        return code >= 400;
    }


}
